package com.example.foobar.dao.service.impl;

import com.example.foobar.entity.DaRemark;
import com.example.foobar.mapper.DaRemarkMapper;
import com.example.foobar.dao.service.DaRemarkDaoService;
import com.example.foobar.param.DaRemarkPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 备注 服务实现类
 *
 * @author 郑英奔
 * @since 2021-06-07
 */
@Slf4j
@Service
public class DaRemarkServiceDaoImpl extends BaseServiceImpl<DaRemarkMapper, DaRemark> implements DaRemarkDaoService {

    @Autowired
    private DaRemarkMapper daRemarkMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveDaRemark(DaRemark daRemark) {
        return super.save(daRemark);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateDaRemark(DaRemark daRemark)  {
        return super.updateById(daRemark);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteDaRemark(Long id)  {
        return super.removeById(id);
    }

    @Override
    public Paging<DaRemark> getDaRemarkPageList(DaRemarkPageParam daRemarkPageParam) {
        Page<DaRemark> page = new PageInfo<>(daRemarkPageParam, OrderItem.desc(getLambdaColumn(DaRemark::getCreateTime)));
        LambdaQueryWrapper<DaRemark> wrapper = new LambdaQueryWrapper<>();
        IPage<DaRemark> iPage = daRemarkMapper.selectPage(page, wrapper);
        return new Paging<DaRemark>(iPage);
    }

    @Override
    public int selectCount(LambdaQueryWrapper<DaRemark> wrapper) {
        return daRemarkMapper.selectCount(wrapper);
    }

    @Override
    public int insert(DaRemark daRemark) {
        return daRemarkMapper.insert(daRemark);
    }

    @Override
    public DaRemark selectOne(LambdaQueryWrapper<DaRemark> wrapper) {
        return daRemarkMapper.selectOne(wrapper);
    }

    @Override
    public void delete(LambdaQueryWrapper<DaRemark> wrapper) {
        daRemarkMapper.delete(wrapper);
    }

}
